Search Java Code Snippets


  Help us in improving the repository. Add new snippets through 'Submit Code Snippet ' link.





#Java - Code Snippets for '#Print elements of a list' - 5 code snippet(s) found

 Sample 1. Display Elements of a List using Java 8 Consumer

List myList = new ArrayList();
      
myList.add("A");
myList.add("B");
myList.add("C");

myList.forEach(System.out::println);

   Like      Feedback     Print elements of a list   java 8  consumer  foreach   list  arraylist  collections


 Sample 2. Print all elements of a ListValuedMap ( Apache Commons ) using forEach and System.out::println

ListValuedMap<String,String> listValuedMap = new ArrayListValuedHashMap();
listValuedMap.put("United States", "Washington");
listValuedMap.put("Canada", "Ottawa");
listValuedMap.put("Canada", "Ottawa");
listValuedMap.put("South Africa", "Pretoria");
listValuedMap.put("South Africa", "Cape Town");
listValuedMap.put("South Africa", "Bloemfontein");

listValuedMap.entries().forEach(System.out::println);

   Like      Feedback     ListValuedMap  apache commons  System.out::println  collections framework   map


 Sample 3. Display Elements of a List

List myList = new ArrayList();
      
myList.add("A");
myList.add("B");
myList.add("C");

System.out.println(myList); // Prints [A, B, C]

   Like      Feedback     Print elements of a list


 Sample 4. Display elements of a List using For loop

List myList = new ArrayList();
      
myList.add("A");
myList.add("B");
myList.add("C");

for(String str:myList){ // prints A B C
   System.out.println(str);
}

   Like      Feedback     Print elements of a list   for loop   arraylist  list  collections


Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner
 Sample 5. Display elements of a List using For Loop and index

List myList = new ArrayList();
      
myList.add("A");
myList.add("B");
myList.add("C");

for(int index=0;index < myList.size(); index++){
   System.out.println(myList.get(index));
}

   Like      Feedback     Print elements of a list   arraylist  list  collections   for loop



Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner